/**
 * Copyright (C) 2007 The AsyncMail Group <asyncmail@googlegroups.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.asyncmail.smtpserver.mock.mina;

import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.mina.common.CloseFuture;

import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoFilterChain;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoService;
import org.apache.mina.common.IoServiceConfig;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TrafficMask;
import org.apache.mina.common.TransportType;
import org.apache.mina.common.WriteFuture;

public class MockIoSession implements IoSession {
    private Map<String, Object> attributes = new HashMap<String, Object>();

    private boolean closed = false;

    private Object attachment;

    private long cTime;

    private SocketAddress sockAddress;

    private SocketAddress remoteAddress;

    List<Object> writtenObjects = new ArrayList<Object>();

    public MockIoSession() {
        cTime = System.currentTimeMillis();
    }

    public CloseFuture close() {
        this.closed = true;
        return null;
    }

    public boolean containsAttribute(String arg0) {
        return attributes.containsKey(arg0);
    }

    public Object getAttachment() {
        return attachment;
    }

    public Object getAttribute(String arg0) {
        return attributes.get(arg0);
    }

    public Set<String> getAttributeKeys() {
        return attributes.keySet();
    }

    public CloseFuture getCloseFuture() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public IoSessionConfig getConfig() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getCreationTime() {
        return cTime;
    }

    public IoFilterChain getFilterChain() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public IoHandler getHandler() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public int getIdleCount(IdleStatus arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public int getIdleTime(IdleStatus arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getIdleTimeInMillis(IdleStatus arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getLastIdleTime(IdleStatus arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getLastIoTime() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getLastReadTime() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getLastWriteTime() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public SocketAddress getLocalAddress() {
        return sockAddress;
    }

    public long getReadBytes() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getReadMessages() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public SocketAddress getRemoteAddress() {
        return remoteAddress;
    }

    public int getScheduledWriteBytes() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public int getScheduledWriteRequests() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public IoService getService() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public SocketAddress getServiceAddress() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public IoServiceConfig getServiceConfig() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public TrafficMask getTrafficMask() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public TransportType getTransportType() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public int getWriteTimeout() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getWriteTimeoutInMillis() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getWrittenBytes() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getWrittenMessages() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public long getWrittenWriteRequests() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public boolean isClosing() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public boolean isConnected() {
        if (closed == true) {
            return false;
        } else {
            return true;
        }
    }

    public boolean isIdle(IdleStatus arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public Object removeAttribute(String arg0) {
        return attributes.remove(arg0);
    }

    public void resumeRead() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public void resumeWrite() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public Object setAttachment(Object arg0) {
        Object tmpAttachment = attachment;
        attachment = arg0;
        return tmpAttachment;
    }

    public Object setAttribute(String arg0) {
        return attributes.put(arg0, "");
    }

    public Object setAttribute(String arg0, Object arg1) {
        return attributes.put(arg0, arg1);
    }

    public void setIdleTime(IdleStatus arg0, int arg1) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public void setTrafficMask(TrafficMask arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public void setWriteTimeout(int arg0) {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public void suspendRead() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public void suspendWrite() {
        throw new UnsupportedOperationException("Unimplemented method");
    }

    public WriteFuture write(Object arg0) {
        writtenObjects.add(arg0);
        return null;
    }

    public void setLocalAddress(SocketAddress sockAddress) {
        this.sockAddress = sockAddress;
    }

    public void setRemoteAddress(SocketAddress remoteAddress) {
        this.remoteAddress = remoteAddress;
    }

}
